package com.test.connection;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yang on 17/3/13.
 */
public class StuGetToken {

    public static List<String> login = new ArrayList<>();
    public static List<String> tokens = new ArrayList<>();

    public static void stuLogin() throws Exception {

        Phone.getPhone();

    String loginUrl = "http://stuapi.knowbox.cn/user/auth/login";
    String baseJson = "{\"source\":\"androidRCStudent\",\"version\":299,\"channel\":\"Knowbox\",\"deviceId\":\"867323021373194\",\"deviceVersion\":\"6.0.1\",\"deviceType\":\"MI_4LTE\",\"token\":\"\",\"transaction\":\"login\",\"loginName\":\"18610790001\",\"password\":\"123456\",\"deviceToken\":\"\"}";

    JSONObject jsonObject = new JSONObject(baseJson);
        for (int i = 0; i < Phone.phones.size(); i ++) {
        jsonObject.put("loginName", Phone.phones.get(i));
        String params = "data=" + jsonObject;
//            System.out.println(params);
        StuGetToken.login.add(ConnectionTest.sendPost(loginUrl, params));
    }

}

    public static void getToken() throws Exception {
        StuGetToken.stuLogin();
        for (int i = 0; i < StuGetToken.login.size(); i++){
            JSONObject jsonObject = new JSONObject(StuGetToken.login.get(i));
            String token = jsonObject.optString("token");
            StuGetToken.tokens.add(token);
        }
    }

}
